import request from '@/config/axios'

// 分页参数接口
export interface PageParam {
  pageNo: number
  pageSize: number
}

// 能耗预警 VO
export interface AlertVO {
  id: number // 预警ID
  deviceId: string // 设备ID
  alertType: string // 预警类型
  alertValue: number // 实际值
  threshold: number // 阈值
  alertTime: Date // 预警时间
  message: string // 预警信息
  status: string // 处理状态
  level: string // 告警级别
}

// 能耗预警分页请求 VO
export interface AlertPageReqVO extends PageParam {
  deviceId?: string
  alertType?: string
  alertValue?: number
  threshold?: number
  alertTime?: Date[]
  message?: string
  status?: string
  createTime?: Date[]
}

// 能耗预警导出请求 VO
export interface AlertExportReqVO {
  deviceId?: string
  alertType?: string
  alertValue?: number
  threshold?: number
  alertTime?: Date[]
  message?: string
  status?: string
  createTime?: Date[]
}

// 能耗预警 API
export const AlertApi = {
  // 查询能耗预警分页
  getAlertPage: async (params: AlertPageReqVO) => {
    return await request.get({ url: `/energy/alert/page`, params })
  },

  // 查询能耗预警详情
  getAlert: async (id: number) => {
    return await request.get({ url: `/energy/alert/get?id=` + id })
  },

  // 新增能耗预警
  createAlert: async (data: AlertVO) => {
    return await request.post({ url: `/energy/alert/create`, data })
  },

  // 修改能耗预警
  updateAlert: async (data: AlertVO) => {
    return await request.put({ url: `/energy/alert/update`, data })
  },

  // 删除能耗预警
  deleteAlert: async (id: number) => {
    return await request.delete({ url: `/energy/alert/delete?id=` + id })
  },

  // 导出能耗预警 Excel
  exportAlert: async (params: AlertExportReqVO) => {
    return await request.download({ url: `/energy/alert/export-excel`, params })
  },

  // 批量上传预警 JSON文件
  uploadAlerts: async (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    return await request.post({ url: '/energy/alert/upload', data: formData })
  }
}
